package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.Score1;
import com.example.demo.service.Score1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/score1")
public class Score1Controller {
    @Autowired
    private Score1Service scoreService;

    @PostMapping("/addScore")
    public Result addScore(@RequestBody Score1 score) {
        scoreService.addScore(score);
        return Result.success();
    }

    @DeleteMapping("/deleteScore/{studentId}")
    public Result deleteScore(@PathVariable Integer studentId) {
        scoreService.deleteScore(studentId);
        return Result.success();
    }

    @PutMapping("/updateScore")
    public Result updateScore(@RequestBody Score1 score) {
        scoreService.updateScore(score);
        return Result.success();
    }

    @GetMapping("/getScore")
    public Result<List<Score1>> getAllScores() {
        List<Score1> scores = scoreService.getAllScores();
        return Result.success(scores);
    }

    @RequestMapping("/select/{id}")
    public Result<Score1> selectScore(@PathVariable("id") Integer studentId) {
        Score1 score = scoreService.getScoreById(studentId);
        return Result.success(score);
    }
}